﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;

namespace Meraz.Core.Repositories
{
    public interface IUrlRedirectRepository : IRepository<UrlRedirect, int> { UrlRedirect GetByUrl(string url); }
    public class UrlRedirectRepository : EFRepositoryBase<UrlRedirect, int>, IUrlRedirectRepository 
    {
        public UrlRedirectRepository() : base() { }
        public UrlRedirectRepository(Data.IMerazContext context) : base(context) { }

        public override UrlRedirect GetById(int id)
        {
            return context.UrlRedirects
                .Where(where1 => where1.ID == id)
                .FirstOrDefault();
        }
        public UrlRedirect GetByUrl(string url)
        {
            return context.UrlRedirects
                .Where(where1 => where1.Start == url)
                .FirstOrDefault();
        }

        public override void Add(UrlRedirect entity)
        {
            context.UrlRedirects.AddObject(entity);
        }

        public override void Delete(UrlRedirect entity)
        {
            context.UrlRedirects.DeleteObject(entity);
        }

        public override List<UrlRedirect> All()
        {
            return context.UrlRedirects.ToList();
        }
    }
}
